<template>
    <el-container>
                <el-main>
        <StElDynamicForm :helper-form="helperForm" :submit-props="{method: 'get',loading: searchLoading,onSubmit:(form,data)=>{queryParams = $stObjectTools.clone(data)}}"
                         :options="computedFormOptions" :origin-prop="{inline: true,labelWidth: '120px'}">
            <template #buttons>
                <el-button v-bind="$stElStyleTools.aiButtonStyle('添加')"
                           @click="$router.push(computedUrl.router.add)" size="mini">添加
                </el-button>
            </template>
        </StElDynamicForm>
        <StElTable ref="steltable" :options="computedTableOptions" @loading="(val)=>{searchLoading = val}" :datas="computedUrl.searchList" :query-params="queryParams">
            <template #append>
                <el-table-column
                        label="操作"
                        width="200">
                    <template #default="{row,column,$index}">
                        <StElButtonGroup :group-param="{row,column,$index}" :operationMoreButtonOptions="{stype: 'link'}" :operations="tableOperations">
                        </StElButtonGroup>
                    </template>
                </el-table-column>

            </template>
        </StElTable>
        </el-main>
    </el-container>
</template>

<script>
    import ScheduleJobMixin from '../ScheduleJobMixin.js'

    import SchedulerRecordUrl from '../record/SchedulerRecordUrl.js'
    export default {
      name: "ScheduleJobSearchList",
      mixins: [ScheduleJobMixin],
      props: {
      },
      computed: {
      },
      data() {
        return {
          queryParams: {},
          searchLoading:  false,

          helperForm: {
          },

          tableOperations: [{
            label: '删除',
            stype: 'link',
            loading: false,
            requestSuccess: ({groupParam}) => {
              // 删除当前行，不重新请求
              this.$refs.steltable.getTableData().splice(groupParam.$index, 1)
            },
            action: ({groupParam}) => {
              return {
                method: 'delete',
                url: this.computedUrl.delete,
                params: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName,schedulerInstanceId: groupParam.row.schedulerInstanceId},
                confirmText: `确定删除 ${groupParam.row.name}吗`
              }
            }
          },
            {
              label: '修改',
              stype: 'link',
              action: ({groupParam}) => {
                this.$router.push({path: this.computedUrl.router.update, query: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName || null,schedulerInstanceId: groupParam.row.schedulerInstanceId||null}})
              }
            },
            {
              label: '复制',
              stype: 'link',
              loading: false,
              requestSuccess: ({groupParam}) => {
                // 删除当前行，不重新请求
                this.$refs.steltable.reloadData()
              },
              action: ({groupParam}) => {
                return {
                  method: 'post',
                  url: this.computedUrl.copy,
                  params: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName || null,schedulerInstanceId: groupParam.row.schedulerInstanceId||null},
                  confirmText: `确定复制 ${groupParam.row.name} 吗`
                }
              }
            },
            {
              label: '执行',
              stype: 'link',
              loading: false,
              requestSuccess: ({groupParam}) => {
                this.$message.success('任务已调度')
              },
              action: ({groupParam}) => {
                return {
                  method: 'post',
                  url: this.computedUrl.executeOnce,
                  params: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName || null,schedulerInstanceId: groupParam.row.schedulerInstanceId||null},
                  confirmText: `确定要执行 ${groupParam.row.name} 吗？该操作会立即执行一次该任务`
                }
              }
            },
            {
              label: '日志',
              stype: 'link',
              action: ({groupParam}) => {
                this.$router.push({path: SchedulerRecordUrl.router.searchList, query: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName || null,schedulerInstanceId: groupParam.row.schedulerInstanceId||null}})
              }
            },
            {
              label: '暂停所有触发器',
              stype: 'link',
              loading: false,
              position: 'more',
              requestSuccess: ({groupParam}) => {
                // 重新加载数据
                this.$refs.steltable.reloadData()
                this.$message.success('暂停成功')
              },
              action: ({groupParam}) => {
                return {
                  method: 'post',
                  url: this.computedUrl.pause,
                  params: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName || null,schedulerInstanceId:groupParam.row.schedulerInstanceId||null},
                  confirmText: `确定将任务  ${groupParam.row.name} 暂停所有触发器 吗`
                }
              }
            },
            {
              label: '恢复所有触发器',
              stype: 'link',
              loading: false,
              position: 'more',
              requestSuccess: ({groupParam}) => {
                // 重新加载数据
                this.$refs.steltable.reloadData()
                this.$message.success('恢复成功')
              },
              action: ({groupParam}) => {
                return {
                  method: 'post',
                  url: this.computedUrl.resume,
                  params: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: groupParam.row.schedulerName || null,schedulerInstanceId: groupParam.row.schedulerInstanceId||null},
                  confirmText: `确定将任务  ${groupParam.row.name} 恢复所有触发器 吗`
                }
              }
            },
          ]
        }
      },
      methods: {
      }
    }
</script>

<style scoped>

</style>